package com.lmx.repoDomain.repository;

import org.springframework.stereotype.Component;

import com.lmx.repoDomain.tmodel.Role;
import com.lmx.repoDomain.tmodel.business.User;

import io.katharsis.queryParams.QueryParams;
import io.katharsis.repository.annotations.JsonApiAddRelations;
import io.katharsis.repository.annotations.JsonApiRelationshipRepository;
import io.katharsis.repository.annotations.JsonApiRemoveRelations;
import io.katharsis.repository.annotations.JsonApiSetRelation;

@JsonApiRelationshipRepository(source = User.class, target = Role.class)
@Component
public class UserToRoleRepository extends BaseRelationRepository<User, Role> {

    @Override
    @JsonApiSetRelation
    public void setRelation(final User user, final Long userId, final String fieldName) {

    }

    @Override
    @JsonApiAddRelations
    public void addRelations(final User source, final Iterable<Long> targetIds, final String fieldName) {
    }

    @Override
    @JsonApiRemoveRelations
    public void removeRelations(final User source, final Iterable<Long> targetIds, final String fieldName) {
    }


    @Override
    public void setRelations(final User source, final Iterable<Long> targetIds, final String fieldName) {
        // TODO Auto-generated method stub

    }

    @Override
    public Role findOneTarget(final Long sourceId, final String fieldName, final QueryParams queryParams) {
        final User user = (User) dslJpaService.findById(sourceId);
        return user.getRole();
    }

    @Override
    public Iterable<Role> findManyTargets(final Long sourceId, final String fieldName, final QueryParams queryParams) {
        return null;
        // final Task task = (Task) dslJpaService.findById(sourceId);
        // return task.getTasktypes();
    }
}
